<?php


//##########################################################

function get_avg_rate($game_id)
{

$game_id = mysql_real_escape_string($game_id);
$query=("SELECT game_id, AVG(rate) AS rating_average FROM rate WHERE game_id='$game_id'");
$result=exec_sql_query($query);
$row = mysql_fetch_array($result);
return $row['rating_average'];

}

//##########################################################

function select_rate($game_id,$member_id,$rate)
{
//voted again or not
//get_game_id($title);
//get_member_id($user);
$member_id = mysql_real_escape_string($member_id);
$query = "SELECT member_id FROM rate WHERE game_id='$game_id' AND member_id='$member_id'";
$result=exec_sql_query($query);
// elegxoume posa apotelesmata vre8hkan
$num_rows = mysql_num_rows($result);
if ($num_rows > 0)
	update_rate($game_id, $member_id, $rate);
else {
	insert_rate($game_id, $member_id, $rate);
	return true;
}
//get_avg_rate($game_id);

}

//############################################################

function update_rate($game_id,$member_id,$rate)
	{
		$game_id = mysql_real_escape_string($game_id);
		$member_id = mysql_real_escape_string($member_id);
		$rate = mysql_real_escape_string($rate);
		
		
		return updateRate($game_id,$member_id,$rate);
	}

//############################################################

function delete_rate($game_id,$member_id,$rate){
		
		$query="Delete from rate where id=$game_id";
		$result= exec_sql_query($query);
		return $result;
 
 }

?>